package com.zxy.supplier_system.server.controller

import com.zxy.supplier_system.server.entity.Authority
import com.zxy.supplier_system.server.service.ProcurementReturnService
import com.zxy.supplier_system.server.utils.IntIdAndName
import org.springframework.data.domain.Pageable
import org.springframework.data.domain.Slice
import org.springframework.web.bind.annotation.*
import java.time.OffsetDateTime

@RestController
@RequestMapping("procurementSuppliers/{supplierId}/returnOrders")
class ProcurementReturnsOrderController(
    private val procurementReturnService: ProcurementReturnService
) {

    @HasAnyAuthority(Authority.采购_退货_创建)
    @PostMapping
    fun createProcurementReturn(@PathVariable supplierId: Int):Int{
        return this.procurementReturnService.createProcurementReturn(supplierId)
    }

    @HasAnyAuthority(Authority.采购_退货_查询)
    @GetMapping
    fun queryProcurementReturnInMarket(@PathVariable supplierId: Int, pageable: Pageable):Slice<QueryProcurementReturnInSupplierResponse>{
        return this.procurementReturnService.queryProcurementReturnInSupplier(supplierId,pageable)
    }

    data class QueryProcurementReturnInSupplierResponse(
        val id:Int,
        val createdBy: IntIdAndName,
        val createdDateTime: OffsetDateTime,
        val goodsKindAmount:Int,
        val submittedDateTime: OffsetDateTime?,
    )



}